<template>
  <div>
      <el-container>
          <!-------------header------------------>
          <el-header style="background-color: #00CB8E;height: 80px">
              <el-row>
                  <el-col :span="6">
                      <a href="/home"><img src="/img/syc.jpg" style="height:80px"></a>
                  </el-col>
                  <!--未登录状态-->
                  <el-col v-if="loginInfo==null" :span="18"><!--v-if="user==null&&doctor==null"-->
                      <el-dropdown @command="handleCommand" style="float:right;margin-right: 50px">
                          <span class="header_span" style="color:white; line-height: 80px">请登录</span>
                          <el-dropdown-menu slot="dropdown" style="width: 150px">
                              <el-dropdown-item command="login">
                                  <span><i class="el-icon-user-solid"></i>用户登录</span>
                              </el-dropdown-item>
                              <el-dropdown-item command="register">
                                  <span><i class="el-icon-user"></i>用户注册</span>
                              </el-dropdown-item>
                          </el-dropdown-menu>
                      </el-dropdown>
                      <el-popover
                              class="el_popover"
                              style="float:right;margin-bottom: 30px"
                              placement="bottom-start"
                              trigger="hover">
                          <div style="height: 100px;width: 100px">
                              <img src="/img/code.png" style="width: 100%" >
                          </div>
                          <div slot="reference" style="height:50px;">
                              <span style="color:white; line-height: 80px" class="header_span">扫码关注公众号</span>
                          </div>
                      </el-popover>

                  </el-col>
                  <!--有用户登录-->
                  <el-col v-else :span="18">
                      <!--用户已登录-->
                      <el-row v-if="loginInfo.role===1||loginInfo.role===2" style="height: 100%" ><!--v-if="user!=null"-->
                              <el-row style="float:right;margin-right: 20px;padding-right: 20px">
                                  <el-col :span="22">
                                   <span  class="logged_in_info">欢迎你！{{loginInfo.name}}</span><!--TODO {{user.name}}-->
                                   <span  class="logged_in_info"><i class="el-icon-s-custom"></i><a href="/order/user/prescription" style="color: white">我的处方</a></span>
                                   <span  class="logged_in_info"><i class="el-icon-s-comment"></i><a href="/order/user/medicine" style="color: white">药品订单</a></span>
                                  </el-col>
                                  <el-col :span="2">
                                      <el-dropdown @command="userCommand">
                                          <img :src="loginInfo.avatar" style="width: 50px;height: 50px;border:2px solid white;border-radius: 50px;margin: 15px 10px 0 0" alt="">
                                          <el-dropdown-menu slot="dropdown">
                                              <el-dropdown-item command="personal">
                                                  <span><i class="el-icon-s-home"></i>个人中心</span>
                                              </el-dropdown-item>
                                              <el-dropdown-item command="logout">
                                                  <span><i class="el-icon-s-custom"></i>退出登录</span>
                                              </el-dropdown-item>
                                          </el-dropdown-menu>
                                      </el-dropdown>
                                  </el-col>
                              </el-row>
                      </el-row>
                      <!--医生已登录-->
                      <el-row v-if="loginInfo.role===3||loginInfo.role===4" style="height: 100%" ><!--v-if="user!=null"-->
                          <el-row style="float:right;margin-right: 20px;padding-right: 20px">
                              <el-col :span="22">
                                  <span  class="logged_in_info">欢迎你！{{loginInfo.name}}</span><!--TODO {{user.name}}-->
                                  <span  class="logged_in_info"><i class="el-icon-s-custom"></i><a href="/order/doc/medicine" style="color: white">患者管理</a></span>
                                  <span  class="logged_in_info"><i class="el-icon-s-comment"></i><a href="/article/postArticle" style="color: white">文章发表</a></span>
                              </el-col>
                              <el-col :span="2">
                                  <el-dropdown>
                                      <img :src="loginInfo.avatar" style="width: 50px;height: 50px;border:2px solid white;border-radius: 50px;margin: 15px 10px 0 0" alt="">
                                      <el-dropdown-menu slot="dropdown">
                                          <el-dropdown-item>
                                              <span><i class="el-icon-s-home"></i><a href="/personal/doctor" style="color:#121511">个人中心</a></span>
                                          </el-dropdown-item>
                                          <el-dropdown-item>
                                              <span><i class="el-icon-s-custom"></i><a href="javascript:void(0)" style="color: #121511" @click="logout()">退出登录</a></span>
                                          </el-dropdown-item>
                                      </el-dropdown-menu>
                                  </el-dropdown>
                              </el-col>
                          </el-row>
                      </el-row>
                    <!--超管已登录-->
                    <el-row v-if="loginInfo.role===5" style="height: 100%" ><!--v-if="user!=null"-->
                      <el-row style="float:right;margin-right: 20px;padding-right: 20px">
                        <el-col :span="22">
                          <span  class="logged_in_info">欢迎你！{{loginInfo.name}}</span><!--TODO {{user.name}}-->
                        </el-col>
                        <el-col :span="2">
                          <el-dropdown @command="doctorCommand">
                            <img :src="loginInfo.avatar" style="width: 50px;height: 50px;border:2px solid white;border-radius: 50px;margin: 15px 10px 0 0" alt="">
                            <el-dropdown-menu slot="dropdown">
                              <el-dropdown-item command="personal">
                                <span><i class="el-icon-s-home"></i>个人中心</span>
                              </el-dropdown-item>
                              <el-dropdown-item command="logout">
                                <span><i class="el-icon-s-custom"></i>退出登录</span>
                              </el-dropdown-item>
                            </el-dropdown-menu>
                          </el-dropdown>
                        </el-col>
                      </el-row>
                    </el-row>
                  </el-col>

              </el-row>
          </el-header>
          <!-------------header------------------>

          <!-------------main------------------>
          <el-main style="padding: 0">
            <router-view/>
          </el-main>
          <!-------------main------------------>

          <!-------------footer------------------>
          <el-footer style="height: 150px;margin: 0 auto;background-color:#cbf4e8;width: 100%;padding: 10px">
              <el-row style="text-align: center;height: 100%;margin: 0 auto;font-size: 10px">
                  <div >
                      <span><a href="">版权声明</a></span>
                      <span><a href="">作者编委</a></span>
                      <span><a href="">四叶草医生</a></span>
                      <span><a href="">四叶草诊所</a></span>
                      <span><a href="">投稿邮箱</a></span>
                  </div><br>
                  <div>
                      <span>Copyright © 2000-2023 DXY All Rights Reserved</span>
                      <span><a class="a" href="">[浙B2-20070219-5]</a></span>
                      <span>浙卫(03)网审[2015] 048号医疗器械网络销售备案编号：</span>
                      <span>(浙杭)网械企备字[2018]第00246号</span>
                  </div><br>
                  <div>
                      <span>第二类医疗器械经营备案凭证：</span>
                      <span>浙杭食药监械经营备20153170号网络文化经营许可证：</span>
                      <span>浙网文[2018]11330-875号食品许可证编号：</span>
                      <span>JY13301080010985</span>
                  </div><br>
                  <div>
                      <span>出版物经营许可证：</span>
                      <span>新出发滨字第0064号人力资源许可证编号：</span>
                      <span>330108202110270036 号</span>
                      <span><a class="a" href="">[(浙) -经营性-2022-0039]</a></span>
                  </div><br>
              </el-row>
          </el-footer>
          <!-------------footer------------------>
      </el-container>
  </div>
</template>
<style>
    body{
        margin: 0 auto;

        background-repeat: no-repeat;
        background-size: 100%;
    }
    /*body样式结束*/

    .el_card{
        height: 250px;
    }
    div>p{
        display: block;
        font-size: 10px;
    }
    .el-card__body{
        padding: 0px;
    }
    .logged_in_info{
        color:white;
        margin-right: 20px;
        line-height: 80px;
    }
    .el-dropdown-link {
        cursor: pointer;
        color: #409EFF;
    }
    .header_span{
        font-size: 18px;
        margin-right: 50px;
        cursor: pointer;
    }
</style>

<script>
import BaseUrl from "@/http/BaseUrl";
import TokenAxios from "@/http/TokenAxios";

export default {
    data(){
        return{
            loginInfo: {
                username: '',
                avatar: '',
                role:''
            }
        }
    },
    methods:{
        loadCurrentLoginInfo(){
           this.loginInfo=JSON.parse(localStorage.getItem('loginInfo'));
           if (this.loginInfo.role===5){
               this.$router.push('/admin/index');
               return;
           }
/*            if (this.loginInfo.role===3||this.loginInfo.role===4){
                this.getDep();
            }*/
        },
        logout(){
            if(confirm("你确认退出吗")){
                let url =BaseUrl.PASSPORT+'/passport/users/logout';
                TokenAxios.post(url).then((response)=>{
                    console.log("url:"+url);
                    let jsonResult=response.data;
                    if(jsonResult.state===20000){
                        this.$message({
                            message: '登出成功',type: 'success'
                        })
                        localStorage.removeItem('loginInfo');
                        // this.$router.push('/login');
                        location.href="/";
                    }
                })
            }
        },
        handleCommand(command) {
            if (command === 'login') {
                // this.$router.push('/login/user')
                location.href="/login/user"
            } else if (command === 'register') {
                // this.$router.push('/reg')
                location.href="/reg"
            }
        },
        userCommand(command){
            if(command==='personal'){
                location.href="/personal/user/account"
            }else if(command==='logout'){
                this.logout();
            }

        },
        doctorCommand(command){
            if(command==='personal'){
                location.href="/personal/doc"
            }else if(command==='logout'){
                this.logout();
            }
        }

    },
    created() {

    },
    mounted() {
        this.loadCurrentLoginInfo();
    }
}
</script>
